import Vue from 'vue'
import VueRouter from 'vue-router'
import request from '../utils/request';

//将url映射到对应的Vue组件
Vue.use(VueRouter)
//requireAuth: 是否需要检查登录
const routes = [
    {
        path: '/',
        name: 'front',
        redirect: "/topview",
        component: () => import('../views/front/Front.vue'),
        meta: {title:'汽车用品商城', path: '汽车用品商城', requireAuth: false},
        children: [
            {path: 'topview', name: 'topview', meta: {title:'汽车用品商城'}, component: () => import('../views/front/TopView.vue'),},
            {path: 'goodList', name: 'goodList', meta: {title:'商品界面'}, component: () => import('../views/front/good/GoodList.vue'),},
            {path: 'goodView/:goodId', name: 'goodview', meta: {title:'商品详情'}, component: () => import('../views/front/good/GoodView.vue'),},
            {path: 'preOrder', name: 'preOrder', meta: {title:'确认订单',requireLogin: true}, component: () => import('../views/front/order/PreOrder.vue'),},
            {path: 'pay', name: 'pay', meta: {title:'支付',requireLogin: true}, component: () => import('../views/front/order/Pay.vue'),},
            {path: 'orderList', name: 'orderList', meta: {title:'我的订单',requireLogin: true}, component: () => import('../views/front/order/OrderList.vue'),},
            {path: 'cart', name: 'cart', meta: {title:'我的购物车',requireLogin: true}, component: () => import('../views/front/good/Cart.vue'),},
            {path: 'person', name: 'person', meta: {title:'个人信息',path: '个人信息',requireAuth: true}, component: () => import('../views/Person.vue'),},
        ]
    },
    //后台管理页面的路由配置
    {
      path: '/manage',
      name:'manage',
      component:()=>import('../views/manage/Manage.vue') ,
        redirect: "/manage/home",
        //在访问 /manage 路径时，会自动重定向到 /manage/home 路径
        meta:{title:'后台', path: '后台',requireAuth: true},
        children: [
            {path: 'home', name: 'home', meta: {title:'主页', path: '主页',requireAuth: true}, component: () => import('../views/manage/Home.vue'),},
            {path: 'person', name: 'person', meta: {title:'个人信息',path: '个人信息',requireAuth: true}, component: () => import('../views/Person.vue'),},
            {path: 'user', name: 'user', meta: {title:'用户管理',path: '系统管理/用户管理',requireAuth: true}, component: () => import('../views/manage/User.vue'),},
            {path: 'carousel', name: 'carousel', meta: {title:'轮播图管理',path: '商品/轮播图管理',requireAuth: true}, component: () => import('../views/manage/good/Carousel.vue'),},
            {path: 'category', name: 'category', meta: {title:'商品分类管理',path: '商品/商品分类管理',requireAuth: true}, component: () => import('../views/manage/good/Category.vue'),},
            {path: 'order',name:'order',meta:{tital:'订单管理',path: '商品/订单管理',requireAuth:true },component:()=>import('../views/manage/Order.vue'),},
            {path: 'good', name: 'good', meta: {title:'商品管理',path: '商品/商品管理',requireAuth: true}, component: () => import('../views/manage/good/Goods.vue'),},
            {path: 'goodInfo', name: 'goodInfo', meta: {title:'商品管理',path: '商品/商品管理/商品信息',requireAuth: true}, component: () => import('../views/manage/good/GoodInfo.vue'),},
        ]
    },
    {
        path: '/login',
        name: 'login',
        // redirect:'/login',
        meta: {
            title: '登录',
        },
        component: () => import(/* webpackChunkName: "about" */ '../views/Login/Login.vue')
    },
    {
        path: '/register',
        name: 'register',
        meta: {
            title: '注册',requireAuth: false,
        },
        component: () => import(/* webpackChunkName: "about" */ '../views/Register.vue')
    },
    {
        path: '/topView',
        name: 'topView',
        // redirect:'/login',
        meta: {
            title: '首页',
        },
        component: () => import('../views/front/TopView.vue')
    },
    {
        path: '/*',
        name: 'notFound',
        meta: {
            title: '找不到页面'
        },
        component: () => import(/* webpackChunkName: "about" */ '../views/404NotFound.vue')
    },

]

const router = new VueRouter({
    mode: 'history',
    base: process.env.BASE_URL,
    routes
})
export default router